package com.yunxin.customui.service.evnethandlerimpl;

import com.yunxin.customui.bean.card.CardBean;
import com.yunxin.customui.bean.card.CardConfig;
import com.yunxin.customui.myinterface.IEventHandler;
import com.yunxin.customui.service.createimpl.CustomCardImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 刷新卡片组件的策略
 *
 * @author lee
 * @date 2021/10/07
 */
@Service
public class RefreshCardImpl implements IEventHandler<CardConfig, Map<String,Object>> {

    @Autowired
    CustomCardImpl cardImpl;

    /**
     * 事件处理
     *
     * @param config          配置
     * @param stringObjectMap 字符串对象映射
     */
    @Override
    public List<EventHandlerResult> eventHandle(CardConfig config, Map<String, Object> stringObjectMap) {
        CardBean component = cardImpl.createComponent(config, stringObjectMap, null);
        EventHandlerResult e = new EventHandlerResult(ResultEventType.Refresh,component);
        return Collections.singletonList(e);
    }
}
